﻿using System;

using Common.Base;

using GameCommon.ComponentInterfaces;

using GameGraphics.Components;

using Microsoft.Xna.Framework;

namespace GameGraphics.Screens.CloudScreen
{
    public class CloudMovement : IAnimation
    {
        private readonly Texture layer1;

        private readonly Texture layer2;

        private readonly Size backgroundSize;

        public CloudMovement(Texture layer1, Texture layer2, Size backgroundSize)
        {
            this.layer1 = layer1;
            this.layer2 = layer2;
            this.backgroundSize = backgroundSize;
        }

        public bool IsFinished { get; private set; }

        public void Update(GameTime gameTime)
        {
            // Scroll layer 1
            if (Math.Abs(this.layer1.SourceDimension.X) > this.backgroundSize.Width)
            {
                this.layer1.SourceDimension.X = 0;
            }

            if (this.layer1.SourceDimension.Y > this.backgroundSize.Height)
            {
                this.layer1.SourceDimension.Y = 0;
            }

            this.layer1.SourceDimension.X -= (int)Math.Ceiling(30 * gameTime.ElapsedGameTime.TotalSeconds);
            this.layer1.SourceDimension.Y -= (int)Math.Ceiling(30 * gameTime.ElapsedGameTime.TotalSeconds);

            // Scroll layer 2
            if (Math.Abs(this.layer2.SourceDimension.X) > this.backgroundSize.Width)
            {
                this.layer2.SourceDimension.X = 0;
            }

            if (this.layer2.SourceDimension.Y > this.backgroundSize.Height)
            {
                this.layer2.SourceDimension.Y = 0;
            }

            this.layer2.SourceDimension.X -= (int)Math.Ceiling(70f * gameTime.ElapsedGameTime.TotalSeconds);
            this.layer2.SourceDimension.Y -= (int)Math.Ceiling(50f * gameTime.ElapsedGameTime.TotalSeconds);
        }
    }
}